﻿using H.Daos;
using H.Daos.Attributes;
using H.Eyes;
using H.Types;
using System;

namespace HModel
{
    /// <summary>
    /// 表示一张图片的信息
    /// </summary>
    [Table("sys_img"), Serializable]
    public class ImgEntity : AbstractEntity, IImgEntity
    {
        /// <summary>
        /// 图片组
        /// </summary>
        [Column("group_id")]
        public int? GroupID { get; set; }

        /// <summary>
        /// 图片的名称(用于人工识别)
        /// </summary>
        [Column("name")]
        public string Name { get; set; }

        /// <summary>
        /// 内部存储基准点偏移的字段
        /// </summary>
        private string _BaseOffsetStr = "";

        /// <summary>
        /// 图片的基点偏移
        /// </summary>
        [Column("base_offset")]
        public string BaseOffsetStr
        {
            get => _BaseOffsetStr; set
            {
                _BaseOffsetStr = value;
                BaseOffset = new Pos(_BaseOffsetStr);
            }
        }

        /// <summary>
        /// 图片的二进制文件数据
        /// </summary>
        [Column("bin", Type = DbType.BLOB)]
        public byte[] Bin { get; set; }

        /// <summary>
        /// 获取图片的基准点偏移
        /// </summary>
        public Pos BaseOffset { get; private set; }

        ///<inheritdoc/>
        public override string ToString()
        {
            return $"{{ImgEntity:{Name}({BaseOffsetStr})}}";
        }

        ///<inheritdoc/>
        public override object Clone()
        {
            return EntityCloner<ImgEntity>.Clone(this);
        }
    }
}
